/******************************************************************************
 * SVN­Version­Information:
 * ­­­­­­­­­­­­­­­­­­­­­­­­---------------------
 * $LastChangedRevision: 133 $
 * $LastChangedBy: MV $
 * $LastChangedDate: 2009-06-25 05:02:32 +0200 (Thu, 25 Jun 2009) $
 * $HeadURL: svn://lvis10.fbm.fht-stuttgart.de/common/Common/src/de/hft_stuttgart/botwar/common/models/PlayerInfo.java $
 ******************************************************************************/
package de.hft_stuttgart.botwar.common.models;

import java.io.Serializable;
import java.util.Calendar;

/**
 * Class to hold all information about a player.
 * @author sdegiorgi@gmail.com, pmv-mail@gmx.de
 */
public class PlayerInfo implements Serializable {

    private final String playerID;
    private final int wonMatches;
    private final int lostMatches;
    private final int drawMatches;
    private final long experience;
    private final int ranking;
    private final Calendar lastOnlineDate;
    private final long playingTime;
    private final boolean online;
    private final long onlineTime;
    private final boolean readyState;
    private final int level;

    /**
     * New player info.
     * @param playerID of a player
     * @param wonMatches of a player
     * @param lostMatches of a player
     * @param drawMatches of a player
     * @param experience of a player
     * @param ranking of a player
     * @param lastOnlineDate of a player
     * @param playingTime of a player
     * @param online of a player
     * @param onlineTime of a player
     * @param level of player
     */
    public PlayerInfo(final String playerID, final int wonMatches,
            final int lostMatches, final int drawMatches, final long experience,
            final int ranking, final Calendar lastOnlineDate,
            final long playingTime, final boolean online,
            final long onlineTime, final int level) {

        this.playerID = playerID;
        this.wonMatches = wonMatches;
        this.lostMatches = lostMatches;
        this.drawMatches = drawMatches;
        this.experience = experience;
        this.ranking = ranking;
        this.lastOnlineDate = lastOnlineDate;
        this.playingTime = playingTime;
        this.online = online;
        this.onlineTime = onlineTime;
        this.readyState = false;
        this.level = level;
    }

    /**
     * Player info.
     * @param playerID of a player
     * @param wonMatches of a player
     * @param lostMatches of a player
     * @param drawMatches of a player
     * @param experience of a player
     * @param ranking of a player
     * @param lastOnlineDate of a player
     * @param playingTime of a player
     * @param online of a player
     * @param onlineTime of a player
     * @param level of a player
     * @param readyState of a player
     */
    public PlayerInfo(final String playerID, final int wonMatches,
            final int lostMatches, final int drawMatches, final long experience,
            final int ranking, final Calendar lastOnlineDate,
            final long playingTime, final boolean online, final long onlineTime,
            final int level, final boolean readyState) {

        this.playerID = playerID;
        this.wonMatches = wonMatches;
        this.lostMatches = lostMatches;
        this.drawMatches = drawMatches;
        this.experience = experience;
        this.ranking = ranking;
        this.lastOnlineDate = lastOnlineDate;
        this.playingTime = playingTime;
        this.online = online;
        this.onlineTime = onlineTime;
        this.level = level;
        this.readyState = readyState;
    }

    /**
     * Returns state if player is ready.
     * @return readyState state if player is ready
     */
    public boolean getReadyState() {
        return readyState;
    }

    /**
     * Returns player id.
     * @return playerID id of player
     */
    public String getPlayerID() {
        return playerID;
    }

    /**
     * Returns number of draw matches.
     * @return drawMatches draw matches
     */
    public int getDrawMatches() {
        return drawMatches;
    }

    /**
     * Returns experience of a player.
     * @return experience of a player
     */
    public long getExperience() {
        return experience;
    }

    /**
     * Returns number of lost matches of a player.
     * @return lostMatches of a player
     */
    public int getLostMatches() {
        return lostMatches;
    }

    /**
     * Returns number of won matches of a player.
     * @return wonMatches of a player
     */
    public int getWonMatches() {
        return wonMatches;
    }

    /**
     * Return ranking of a player.
     * @return ranking of a player
     */
    public int getRanking() {
        return ranking;
    }

    /**
     * Return last online date of a player.
     * @return lastOnlineDate of a player
     */
    public Calendar getLastOnlineDate() {
        return lastOnlineDate;
    }

    /**
     * Returns playing time of a player.
     * @return playingTime of a player
     */
    public long getPlayingTime() {
        return playingTime;
    }

    /**
     * Return true or false if a player is online.
     * @return online true or false if a player is online
     */
    public boolean isOnline() {
        return online;
    }

    /**
     * Return online time of a player.
     * @return onlineTime of a player
     */
    public long getOnlineTime() {
        return onlineTime;
    }

    /**
     * Return level of player.
     * @return level of player
     */
    public int getLevel() {
        return level;
    }


    /**
     * Overrides method equals.
     * @param obj to compare
     * @return boolean true or false
     */
    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        PlayerInfo pInfo = (PlayerInfo) obj;
        if (this.getPlayerID().equals(pInfo.getPlayerID())) {
            return true;
        }
        return false;
    }

    /**
     * Overrides method hashCode
     * @return hash code
     */
    @Override
    public int hashCode() {
        int hash = 5;
        hash = 23 * hash + this.getPlayerID().hashCode();
        return hash;
    }

    /**
     * Overrides method toString.
     * @return Text representation of this instance.
     */
    @Override
    public String toString() {
        return String.format("%d. rank for player %s with" +
                "\n\twon matches: %d" +
                "\n\tlost matches: %d" +
                "\n\tdraw matches: %d" +
                "\n\texperience: %d" +
                "\n\tplaying time %d" +
                "\n\tonline now: %b" +
                "\n\tonline time: %d" +
                "\n\tlevel: %d" +
                "\n\tlast online time: %11$tD %11$tT %11$tH",
                this.getRanking(), this.getPlayerID(),
                this.getWonMatches(), this.getLostMatches(),
                this.getDrawMatches(), this.getExperience(),
                this.getPlayingTime(), this.isOnline(),
                this.getOnlineTime(), this.getLevel(),
                this.getLastOnlineDate());
    }
}

